package com.example.controller.admin;

import com.example.base.BaseController;
import com.example.base.ResultBaseController;
import com.example.entity.User;
import com.example.service.UserService;
import com.example.vo.Result;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: aimi
 * @Create: 2024-05-27
 **/
@RestController
@Slf4j
@RequestMapping("/admin/user/")
public class AdminUserController extends ResultBaseController<UserService, User> {
    @Resource
    private UserService userService;

    @Override
    public Result<User> plus(@RequestBody @NotEmpty User entity) {
        log.info("管理员添加用户：{}",entity);
        userService.addUser(entity);
        entity.setPassword("");
        return Result.ok(entity);
    }

    @PutMapping("/updateStatus/{userId}")
    public Result<Boolean> updateStatus(@PathVariable Integer userId){
        User user = baseService.getById(userId);
        user.setDisabled(user.getDisabled() == null || !user.getDisabled());
        userService.updateById(user);
        return Result.ok();
    }
}